<template>
  <div class="collect-page">
     <van-nav-bar fixed title="我的收藏" />
      <van-list
        v-model="loading"
        :finished="finished"
        finished-text="没有更多了"
        @load="onLoad"
      >
        <ArticleItem v-for="(item, i) in list" :key="i" :item="item"></ArticleItem>
      </van-list>
  </div>
</template>

<script>
import { getCollect } from '@/api/article'
export default {
  name: 'CollectPage',
  data () {
    return {
      list: [],
      loading: false,
      finished: false,
      page: 1
    }
  },
  methods: {
    // async onLoad () {
    //   // 异步更新数据
    //   const data = await getCollect({
    //     optType: 1,
    //     pageSize: 5,
    //     page: this.page
    //   })
    //   console.log(data.data.rows)
    //   this.list.push(...data.data.rows)
    //   this.loading = false
    //   this.page++

    //   if (this.page > data.pageTotal) {
    //     this.finished = true
    //   }
    // }
    async onLoad () {
      // 异步更新数据
      const { data } = await getCollect({ page: this.page })
      this.list.push(...data.rows)
      this.loading = false
      this.page++

      if (this.page > data.pageTotal) {
        this.finished = true
      }
    }
  }
}
</script>

<style lang="less" scoped>
.collect-page {
  margin-bottom: 50px;
  margin-top: 44px;
}
</style>
